package org.wmq.positiontoshop.common;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.TimeUnit;

@Component
public class LocalCache {
    private Cache<String,String> cache;
    @PostConstruct
    public void init(){
        cache = Caffeine.newBuilder().maximumSize(1000).expireAfterWrite(10, TimeUnit.SECONDS).build();
    }

    public void put(String key,String value){
        cache.put(key,value);
    }

    public String get(String key){
        return cache.getIfPresent(key);
    }

    public void remove(String key){
        cache.invalidate(key);
    }

}
